﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;

namespace forever
{
    /// <summary>
    /// hhhhhhhhhhhhhhhhhhhhhh
    /// vs 2012
    /// 啦啦啦 德玛西亚
    /// 推 
    /// </summary>
    class Program
    {
        static void Main1(string[] args)
        {
            Console.WriteLine("runging......");
            Stopwatch sw = new Stopwatch();
            Console.WriteLine("{0:n}", double.MaxValue);
            var iMax = int.MaxValue;
            sw.Start();
            for (int i = 0; i < iMax; i++) ;
            sw.Stop();


            Console.WriteLine(sw.ElapsedTicks);

            var xx = sw.ElapsedTicks;
            var xxx = ((double)xx) / Stopwatch.Frequency;
            Console.WriteLine(xxx + "                 .........");


            var dM = ((double.MaxValue / int.MaxValue) * xx) / Stopwatch.Frequency;
            var d = dM / 60 / 60 / 24 / 365 / 1000;//世纪
            Console.WriteLine(dM);
            var r = double.Parse(d.ToString(), System.Globalization.NumberStyles.Float);
            Console.WriteLine(r);

            var longMax = ((double)(long.MaxValue / int.MaxValue) * xx) / Stopwatch.Frequency;
            longMax = longMax / 60 / 60 / 24 / 365;
            Console.WriteLine(longMax);
            Console.ReadKey();
        }

        static void Main2(string[] args)
        {
            var size = sizeof(int);
            Console.WriteLine("int  " + size + "   " + x(int.MaxValue));

            size = sizeof(Int16);
            Console.WriteLine("Int16  " + size);

            size = sizeof(Int32);
            Console.WriteLine("Int32  " + size);

            size = sizeof(Int64);
            Console.WriteLine("Int64  " + size);

            size = sizeof(long);
            Console.WriteLine("long  " + size);

            size = sizeof(double);
            Console.WriteLine("double  " + size);

            size = sizeof(decimal);
            Console.WriteLine("decimal  " + size);

            Console.ReadKey();
        }
        static string x(object o)
        {
            unsafe
            {
                int i = 1;
                int* ii = &i;
                *ii = 99;
                Console.WriteLine(ii->ToString());
            }
            return string.Format("{0}", o);
        }



        class A
        {
            public int Int { get; set; }
            public string String { get; set; }
            public B B { get; set; }
        }
        [StructLayout(LayoutKind.Sequential)]
        class B
        {
            public int Int { get; set; }
            public string String { get; set; }
        }
        [StructLayout(LayoutKind.Sequential)]
        struct C
        {
            public int Int { get; set; }
            public string String { get; set; }
            public B B { get; set; }
        }

        [StructLayout(LayoutKind.Explicit)]
        public struct D
        {
            [FieldOffset(0)]
            public Int64 Int64;//8
            [FieldOffset(0)]
            public bool Bool;//8
            [FieldOffset(0)]
            public Double Double;//8
            //[FieldOffset(0)]
            //public Decimal Decimal;//16
        }
        class Ex : Exception
        {
            public override int GetHashCode()
            {
                return base.GetHashCode() + 1;
            }
        }


        static unsafe void Main(string[] args)
        {

            int[,] gg = new int[20, 20];

          

            
            A a = new A();
            C c = new C();
            D d = new D();
            var pC = &d;

            pC->Int64 = 99;
            var address = (int)pC;
            var p = &address;
            *p = 0;
            Console.WriteLine(pC->Bool);
            Console.WriteLine((int)pC);
            Console.WriteLine((int)p);


            IntPtr ip = (IntPtr)p;
            //Marshal.ReadInt32(ip,99999999);
            var b1 = Marshal.ReadByte(ip);
            //var _char = (Char)b1;
            Console.Read();
        }
    }
}
